/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DatosEmpresaUI.java
 *
 * Created on 5/01/2012, 04:48:06 PM
 */
package gui.panel;

import dao.CiudadDao;
import dao.DatosEmpresaDao;
import dao.DepartamentosDao;
import java.util.ArrayList;
import java.util.List;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import pojos.Ciudad;
import pojos.DatosEmpresa;
import pojos.Departamentos;
import util.LoggingBindingListener;


/**
 *
 * @author Usuario
 */
public class DatosEmpresaUI extends javax.swing.JPanel {
    
    //Beans y lista para desplegar en UI

    private List<Departamentos> listDepartamentos=new ArrayList<Departamentos>();
    private List<Ciudad> listCiudades=new ArrayList<Ciudad>();
    private DatosEmpresa datosEmpresa;

    
    private DepartamentosDao dptosDao=new DepartamentosDao();
    private CiudadDao ciudadDao=new CiudadDao();
    private DatosEmpresaDao datosDao=new DatosEmpresaDao();
    
    

    /** Creates new form DatosEmpresaUI */
    public DatosEmpresaUI() {
        listDepartamentos=dptosDao.findAll();
        
        //se obtiene el último elemento de la tabla si existe
        datosEmpresa=datosDao.getLastItem();
        
        //Variable temporal para mostrar la ciudad almacenada
        Ciudad tmpCiudad;
        //si no hay datos de empresa en la bd
        if(datosEmpresa==null){
            datosEmpresa=new DatosEmpresa();
            //si no hay datos carga la lista de las ciudades de amazonas
            listCiudades = ciudadDao.findByDpto(listDepartamentos.get(0));
            tmpCiudad=listCiudades.get(0);
        }else{
            //si hay datos carga las ciudades del dpto asociado
            listCiudades = ciudadDao.findByDpto(datosEmpresa.getCiudad().getDepartamentos());
            tmpCiudad=datosEmpresa.getCiudad();
        }
        initComponents();
        this.llenarCiudades(listCiudades);
        comboDptos.setSelectedItem(tmpCiudad.getDepartamentos());
        comboCiudad.setSelectedItem(tmpCiudad);
        
        //decoradores para comboBox
        AutoCompleteDecorator.decorate(comboDptos);
        AutoCompleteDecorator.decorate(comboCiudad);

        bindingGroup.addBindingListener(new LoggingBindingListener(msgLabel));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        emailValidator1 = new validation.EmailValidator();
        numbersValidator1 = new validation.NumbersValidator();
        requiredNumbersValidator1 = new validation.RequiredNumbersValidator();
        requiredStringValidator1 = new validation.RequiredStringValidator();
        intConverter1 = new validation.converter.IntConverter();
        longConverter1 = new validation.converter.LongConverter();
        longValidator1 = new validation.LongValidator();
        contenedor = new org.jdesktop.swingx.JXPanel();
        lCod = new org.jdesktop.swingx.JXLabel();
        lNombre = new org.jdesktop.swingx.JXLabel();
        lDireccion = new org.jdesktop.swingx.JXLabel();
        lDpto = new org.jdesktop.swingx.JXLabel();
        lTelefono = new org.jdesktop.swingx.JXLabel();
        lFax = new org.jdesktop.swingx.JXLabel();
        textCod = new org.jdesktop.swingx.JXTextField();
        textNombre = new org.jdesktop.swingx.JXTextField();
        textDir = new org.jdesktop.swingx.JXTextField();
        textTel = new org.jdesktop.swingx.JXTextField();
        textFax = new org.jdesktop.swingx.JXTextField();
        comboDptos = new org.jdesktop.swingx.JXComboBox();
        lCiudad = new org.jdesktop.swingx.JXLabel();
        comboCiudad = new org.jdesktop.swingx.JXComboBox();
        lEmail = new org.jdesktop.swingx.JXLabel();
        textEmail = new org.jdesktop.swingx.JXTextField();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        lRegimen = new org.jdesktop.swingx.JXLabel();
        lResolucion = new org.jdesktop.swingx.JXLabel();
        lLeyenda = new org.jdesktop.swingx.JXLabel();
        lDesde = new org.jdesktop.swingx.JXLabel();
        lHasta = new org.jdesktop.swingx.JXLabel();
        textReg = new org.jdesktop.swingx.JXTextField();
        textResol = new org.jdesktop.swingx.JXTextField();
        textDesde = new javax.swing.JTextField(10);
        textHasta = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        textLeyenda = new javax.swing.JTextArea();
        msgLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        contenedor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Empresa", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        lCod.setText("Código tributario*:");

        lNombre.setText("Nombre*:");

        lDireccion.setText("Dirección:");

        lDpto.setText("Departamento:");

        lTelefono.setText("Teléfono:");

        lFax.setText("Fax:");

        textCod.addKeyListener(new validation.KeyLimiter(15, textCod));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.codTrib}"), textCod, org.jdesktop.beansbinding.BeanProperty.create("text"), "Codigo tributario");
        binding.setValidator(requiredStringValidator1);
        bindingGroup.addBinding(binding);

        textCod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textCodActionPerformed(evt);
            }
        });

        textNombre.addKeyListener(new validation.KeyLimiter(40, textNombre));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.nombre}"), textNombre, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(requiredStringValidator1);
        bindingGroup.addBinding(binding);

        textDir.addKeyListener(new validation.KeyLimiter(50, textDir));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.direccion}"), textDir, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        textTel.addKeyListener(new validation.KeyLimiter(15, textTel));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.telefono}"), textTel, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(numbersValidator1);
        bindingGroup.addBinding(binding);

        textFax.addKeyListener(new validation.KeyLimiter(15, textFax));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.fax}"), textFax, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(numbersValidator1);
        bindingGroup.addBinding(binding);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${listDepartamentos}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, comboDptos);
        bindingGroup.addBinding(jComboBoxBinding);

        comboDptos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboDptosActionPerformed(evt);
            }
        });

        lCiudad.setText("Ciudad");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.ciudad}"), comboCiudad, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        lEmail.setText("Email:");

        textEmail.addKeyListener(new validation.KeyLimiter(50, textEmail));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.email}"), textEmail, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(emailValidator1);
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout contenedorLayout = new javax.swing.GroupLayout(contenedor);
        contenedor.setLayout(contenedorLayout);
        contenedorLayout.setHorizontalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lCod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lDpto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(206, 206, 206)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textCod, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(textFax, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(textTel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(textDir, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(textNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, contenedorLayout.createSequentialGroup()
                        .addComponent(comboDptos, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(lCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(comboCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(textEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))
                .addContainerGap())
        );
        contenedorLayout.setVerticalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lCod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textCod, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lDpto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboDptos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(comboCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Factura", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        lRegimen.setText("Régimen tributario*:");

        lResolucion.setText("Resolución de autorización facturación*:");

        lLeyenda.setText("Leyenda en el pie de página:");

        lDesde.setText("Rango desde*:");

        lHasta.setText("Rango hasta*:");

        textReg.addKeyListener(new validation.KeyLimiter(50, textReg));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.regimentrib}"), textReg, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(requiredStringValidator1);
        bindingGroup.addBinding(binding);

        textResol.addKeyListener(new validation.KeyLimiter(60, textResol));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.resolucionAutor}"), textResol, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setValidator(requiredStringValidator1);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.rangoDesde}"), textDesde, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(longConverter1);
        binding.setValidator(longValidator1);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.rangoHasta}"), textHasta, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(longConverter1);
        binding.setValidator(longValidator1);
        bindingGroup.addBinding(binding);

        textLeyenda.setColumns(20);
        textLeyenda.setLineWrap(true);
        textLeyenda.setRows(5);
        textLeyenda.setWrapStyleWord(true);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${datosEmpresa.piePag}"), textLeyenda, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        textLeyenda.addKeyListener(new validation.KeyLimiter(100, textLeyenda));
        jScrollPane1.setViewportView(textLeyenda);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lResolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lLeyenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(102, 102, 102)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                    .addComponent(textResol, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                    .addComponent(textReg, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                    .addComponent(textDesde, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                    .addComponent(textHasta, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE))
                .addContainerGap())
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textResol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lResolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lLeyenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        msgLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        msgLabel.setForeground(new java.awt.Color(204, 0, 0));
        msgLabel.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                msgLabelComponentResized(evt);
            }
        });

        jButton1.setText("Guardar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Cerrar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(contenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(msgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(129, 129, 129)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(48, 48, 48))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(contenedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton3))
                    .addComponent(msgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void textCodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textCodActionPerformed

        // TODO add your handling code here:}//GEN-LAST:event_textCodActionPerformed
    }
        private void comboDptosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboDptosActionPerformed
        // TODO add your handling code here:}//GEN-LAST:event_comboDptosActionPerformed
        Departamentos seleccionado = (Departamentos) comboDptos.getSelectedItem();
        if (seleccionado != null) {
            listCiudades = ciudadDao.findByDpto(seleccionado);
            comboCiudad.removeAllItems();
            for (Ciudad c : listCiudades) {
                comboCiudad.addItem(c);
            }
        }
    }        
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
            try{
                datosDao.create(datosEmpresa);
                msgLabel.setText("La información se ha guardado correctamente");
            }catch(Exception e){
                msgLabel.setText("Error: "+ e.getMessage());
            }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void msgLabelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_msgLabelComponentResized
        // TODO add your handling code here:
        
    }//GEN-LAST:event_msgLabelComponentResized

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXComboBox comboCiudad;
    private org.jdesktop.swingx.JXComboBox comboDptos;
    private org.jdesktop.swingx.JXPanel contenedor;
    private validation.EmailValidator emailValidator1;
    private validation.converter.IntConverter intConverter1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXLabel lCiudad;
    private org.jdesktop.swingx.JXLabel lCod;
    private org.jdesktop.swingx.JXLabel lDesde;
    private org.jdesktop.swingx.JXLabel lDireccion;
    private org.jdesktop.swingx.JXLabel lDpto;
    private org.jdesktop.swingx.JXLabel lEmail;
    private org.jdesktop.swingx.JXLabel lFax;
    private org.jdesktop.swingx.JXLabel lHasta;
    private org.jdesktop.swingx.JXLabel lLeyenda;
    private org.jdesktop.swingx.JXLabel lNombre;
    private org.jdesktop.swingx.JXLabel lRegimen;
    private org.jdesktop.swingx.JXLabel lResolucion;
    private org.jdesktop.swingx.JXLabel lTelefono;
    private validation.converter.LongConverter longConverter1;
    private validation.LongValidator longValidator1;
    private javax.swing.JLabel msgLabel;
    private validation.NumbersValidator numbersValidator1;
    private validation.RequiredNumbersValidator requiredNumbersValidator1;
    private validation.RequiredStringValidator requiredStringValidator1;
    private org.jdesktop.swingx.JXTextField textCod;
    private javax.swing.JTextField textDesde;
    private org.jdesktop.swingx.JXTextField textDir;
    private org.jdesktop.swingx.JXTextField textEmail;
    private org.jdesktop.swingx.JXTextField textFax;
    private javax.swing.JTextField textHasta;
    private javax.swing.JTextArea textLeyenda;
    private org.jdesktop.swingx.JXTextField textNombre;
    private org.jdesktop.swingx.JXTextField textReg;
    private org.jdesktop.swingx.JXTextField textResol;
    private org.jdesktop.swingx.JXTextField textTel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public List<Departamentos> getListDepartamentos() {
        return listDepartamentos;
    }

    public List<Ciudad> getListCiudades() {
        return listCiudades;
    }

    public DatosEmpresa getDatosEmpresa() {
        return datosEmpresa;
    }

    public void setListDepartamentos(List<Departamentos> listDepartamentos) {
        this.listDepartamentos = listDepartamentos;
    }

    public void setListCiudades(List<Ciudad> listCiudades) {
        this.listCiudades = listCiudades;
    }

    public void setDatosEmpresa(DatosEmpresa datosEmpresa) {
        this.datosEmpresa = datosEmpresa;
    }

    private void llenarCiudades(List<Ciudad> ciudades){
        comboCiudad.removeAllItems();
        for(Ciudad c: ciudades){
            comboCiudad.addItem(c);
        }
    }
}
